import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wwy
 * Date: 2024-05-01
 * Time: 14:28
 */
public class GongYueShu {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int a= scanner.nextInt();
        int b=scanner.nextInt();
        while(b!=0){
            int t=b;
            b=a%b;
            a=t;
        }
        System.out.println(a);
    }
}
